#include <iostream>
#include <windows.h>

#include "dllTest60.h"
#include "uThread.h"
#include "uCritSec.h"
#include "pumpMsg.h"

int iVar,iProc,iJet;
unsigned char BoolIn1, BoolIn2;
BOOL bRet;
MSG msg;

void DllTest60(unsigned char, unsigned char);
void PumpMessages();

sCriticalSection cs;
sThread t1(TRUE);

void Exec_t1()
{
	std::cout<<"\nThread-1:In CRITICAL SECTION";
	LVDLLStatus(NULL,0,NULL);

	while (iProc==1)
	{
		if (iVar==10)
		{
			if (iJet==0)
			{
				std::cout<<"\n\t1_"<<iVar;
				Sleep(50);
				iJet=1;
			}
		}
		else if (iVar==96)
		{
			if (iJet==0)
			{
				std::cout<<"\t1_"<<iVar;
				Sleep(50);
				iJet=1;
			}
		}
	}
	//A function from a Dll made with LV
	DllTest60(&BoolIn1, &BoolIn2);	//This function makes a beep sound.

	PumpMessages();

//	DllTest60(&BoolIn1, &BoolIn2);

	std::cout<<"\nThread-1:Out of CRITICAL SECTION";
}

void main()
{
	BoolIn1=TRUE;
	BoolIn2=TRUE;
	iProc=1;

	void sub();

	std::cout<<"\nMain started.";

	sub();

	for (int j=0; j<100; j++)
	{
		iJet=0;
		iVar=j*2;
		Sleep(100);
	}

	iProc=0;
	std::cout<<"\n.......................";
	Sleep(100);
	std::cout<<"\nProgram about to die...";
	std::cin.get();
}

void sub()
{
	t1.OnExecute = Exec_t1;
	t1.Resume();
}